Skip to content

make non-ascii characters in logger messages legible #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2024
Merged

make non-ascii characters in logger messages legible #203

merged 1 commit into from
May 15, 2024

Conversation

joshdavham
Copy link
Contributor

@joshdavham joshdavham commented May 14, 2024

Currently, logger messages containing non-ascii characters are displayed as unicode escape sequences, making them illegible to anyone reading the logs.

For example,

from firebase_functions import logger
logger.log("こんにちは")
# outputs: {"severity": "NOTICE", "message": "\u3053\u3093\u306b\u3061\u306f"}

This behavior is due to the logger module making use of json.dumps which by default only outputs ascii characters (see here).

I added ensure_ascii=False to wherever json.dumps was used for the logger messages and now output for these logs should be legible.

logger.log("こんにちは")
# outputs: {"severity": "NOTICE", "message": "こんにちは"}

Let me know if there are any questions or issues 👍

Copy link
Contributor

@exaby73 exaby73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you 🙌

@exaby73 exaby73 merged commit 187c968 into firebase:main May 15, 2024
8 checks passed
@joshdavham joshdavham deleted the logger-support-non-ascii branch May 15, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants